# Maintainer: AlexWMF <alexxwmf@gmail.com>

_realname=qca
pkgbase=mingw-w64-${_realname}-qt5
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-qt5"
pkgver=2.3.0
pkgrel=1
pkgdesc="Qt Cryptographic Architecture (mingw-w64)"
arch=('any')
url="http://delta.affinix.com/qca/"
license=('LGPL')
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-qt5-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-qt5-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-ca-certificates"
         "${MINGW_PACKAGE_PREFIX}-cyrus-sasl"
         "${MINGW_PACKAGE_PREFIX}-gnupg"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-nss"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-qt5")
install=${_realname}-qt5-git-${CARCH}.install
source=("https://download.kde.org/stable/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.xz"{,.sig}
        "cyrus_sasl_linking.patch"
        "qt5-custom-dirs.patch"
        "qca-mingw-pkg-config.patch"
        "qca-mingw-custom-certificates.patch"
        "qca-mingw-link-to-release.patch"
        "qca-win-build-fix.patch")
sha256sums=('1d68ef41a1b61dc9786beb923a68902a6276a77cced5e5ea7ff985ef113932d7'
            'SKIP'
            'a5eeb6e2c3e884b54dc3837509d1cbde4611623a2888775ddb7e3868b1623e7c'
            '54b4a38ebb80939dbe6de149e6da8bffb98784c7358ffff4a940c4c9212296b2'
            'ba7e835e30306f415168b1f8c31adda7e6c3881c96ad74d0bcb52466113c5ba4'
            '57602e5272a079ca1e8f4b4452030094010c7a6b33ed4606e1497cd0b4126717'
            '037b615f8b6f609112383b69e6050e7c939b12b0c7c0fa210a58e075c0d1c589'
            'b031ceac3ed4e1228349545cf536f75fd6e21a3cfb6a0412e5eb87c1f45b1bbc')
validpgpkeys=('CB9387521E1EE0127DA804843FDBB55084CC5D84')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/cyrus_sasl_linking.patch
  patch -p1 -i ${srcdir}/qt5-custom-dirs.patch
  patch -p1 -i ${srcdir}/qca-mingw-pkg-config.patch
  patch -p1 -i ${srcdir}/qca-mingw-custom-certificates.patch
  patch -p1 -i ${srcdir}/qca-mingw-link-to-release.patch
  patch -p1 -i ${srcdir}/qca-win-build-fix.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  #QC_CERTSTORE_PATH=${MINGW_PREFIX}/ssl/certs/ca-bundle.crt
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;DQC_CERTSTORE_PATH=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DWITH_botan_PLUGIN=no \
    -DBUILD_TESTS=False \
    -DQCA_SUFFIX=qt5 \
    -DQCA_SYSTEMSTORE_PATH=../ssl/certs/ca-bundle.crt \
    -DQCA_INSTALL_IN_QT_PREFIX=ON \
    ../${_realname}-${pkgver}.

  make ${MAKEFLAGS}
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
